import java.util.ArrayList;

public class Frame
{
	protected ArrayList<Integer> bowls;
	protected int availableAttempts = 2;
	protected Frame nextFrame;
	public Frame()
	{
		bowls = new ArrayList<Integer>();
	}
	public void bowl(int i)
	{
		bowls.add(i);
		useAttempt();
		if (i == 10)
		{
			bowls.add(0);
			useAttempt();
		}
	}
	public void setNext(Frame f)
	{
		this.nextFrame = f;
	}
	public int getAttempts()
	{
		return this.availableAttempts;
	}
	public void useAttempt()
	{
		this.availableAttempts--;
	}
	public boolean isStrike()
	{
		return this.getInitialBowl() == 10;
	}
	public boolean isSpare()
	{
		return (!isStrike()) && (this.getInitialBowl() + this.getNextBowl() == 10);
	}
	public int getInitialBowl()
	{
		return bowls.get(0);
	}
	public int getNextBowl()
	{
		return bowls.get(1);
	}
	public int getScore()
	{
		int score = 0;
		if (this.isSpare())
			score = 10 + nextFrame.bowls.get(0);
		else if (this.isStrike())
		{
			if (nextFrame.isStrike())
			{
				score = this.getInitialBowl() + nextFrame.getInitialBowl() + nextFrame.nextFrame.getInitialBowl();
			}
			else
			{
				score = this.getInitialBowl() + nextFrame.getInitialBowl() + nextFrame.getNextBowl();
			}
		}
		else
			score = getInitialBowl() + getNextBowl();
		return score;
	}
}
